#!/usr/bin/env python2
# coding: utf-8

import lab2
import re

for s in ['ab', 'aa', 'aaa', 'ababababaa', 'a', 'b', '']:
    print "%s\t%s" % (s, lab2.simple_m1(s))

for s in ['ab', 'aa', 'aabb', 'aaaaa', 'aaaa', '']:
    print lab2.dfa(lab2.transitions1, [1], s)

# DFAFactory
m1 = lab2.make_dfa(lab2.transitions1, [1])
print m1('ab')
print m1('aa')
print m1('aaa')

tr2 = [{} for i in range(4)]
tr2[0]['a'] = 0
tr2[0]['b'] = 1
tr2[1]['a'] = 2
tr2[1]['b'] = 3
tr2[2]['a'] = 1
tr2[2]['b'] = 0
tr2[3]['a'] = 2
tr2[3]['b'] = 3
m2 = lab2.make_dfa(tr2, [0, 3])
print m2('aaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
print m2('aaaaaaaaaa')
print m2('aaaaaaaaaaaaaaaaaaaababaaaaaaaaaaaaaaaaabaabbbbbbbbbbbbbbbbbbbbbbb')
print
print m2('aabb')
print m2('')
print m2('aabba')
print m2('a')

# starts w/ 0 and has odd length or starts w/ 1 and has even length
lab2.print_match('^(0.(..)*|1(..)*)$', '00')
lab2.print_match('^(0.(..)*|1(..)*)$', '000')
lab2.print_match('^(0.(..)*|1(..)*)$', '10')
lab2.print_match('^(0.(..)*|1(..)*)$', '100')
print
# is not '11' or '111'
lab2.print_match('^(.|(00|01|10)|(000|001|010|011|100|110)|000.*)$', '111')
lab2.print_match('^([01]*0[01]*|1|1111*|)$', '11')
print
# contains 1 at every odd position
lab2.print_match('^(1[01])*(1|)$', '111')
lab2.print_match('^(1[01])*(1|)$', '101')
lab2.print_match('^(1[01])*(1|)$', '11')
lab2.print_match('^(1[01])*(1|)$', '100010101')
print
# >= 2x'0' <=1x'1'
#lab2.print_match('^((1*01*)|(0*10*)|\1\2\1|\2\1\1|\1\1\2)$','')
lab2.print_match('^0*(00|100|010|001)0*$', '0000010')
lab2.print_match('^0*(00|100|010|001)0*$', '0100010')
lab2.print_match('^0*(00|100|010|001)0*$', '01')
print

#  Д/З:
# - не меньше 3-х '1'
# - не содержит подстроку '110'
# - не более 5-ти символов
# - явл. пустой строкой или нулём
# - сод. четное число нулей, или в точности две единицы
# - функция, получ. число n и возвращает dfa, кот. допускает бинарные строки, явл. двоичным представлением чисел, кратных n
#     m = f(2)
#     m('101') #false
#     m('10') #true

# regex для автомата m1
r1 = '^(b*a(a|b)(b*a(a|b))*b*a|b*a)$'
